package com.gjp.config;

import com.gjp.interceptor.BasePathInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * Created by 郭金鹏 on 2018/4/1.
 */
@Configuration
public class WebMvcAppConfig extends WebMvcConfigurerAdapter {

    /**
     * 配置BasePath项目根路径，提供给前端
     * @return
     */
    @Bean
    public HandlerInterceptor getBasePathInterceptor(){
        return new BasePathInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getBasePathInterceptor()).addPathPatterns("/**");
        super.addInterceptors(registry);
    }
}
